package com.abc.logtest.manager;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.LogManager;
import java.util.logging.Logger;

import com.abc.logtest.Constants;

public class JavaUtilLogManager {
	
	private static JavaUtilLogManager javaUtilLogManager = new JavaUtilLogManager();
	
	private static boolean hasConfig = false;
	
	private Logger logger = Logger.getLogger(JavaUtilLogManager.class.getName());
	
	private LogManager logManager = LogManager.getLogManager();
	
	private static void readConfig(){
		
		ClassLoader classLoader = JavaUtilLogManager.class.getClassLoader();
	
		InputStream configStream = classLoader.getResourceAsStream(Constants.JAVA_UTIL_LOG_CONFIG);
		
		try {
			javaUtilLogManager.logManager.readConfiguration(configStream);
			javaUtilLogManager.logManager.addLogger(javaUtilLogManager.logger);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public JavaUtilLogManager(){

	}
	
	public static Logger getLogger(){
		synchronized (javaUtilLogManager) {
			if(!hasConfig){
				readConfig();
				hasConfig = true;
			}
		}
		return javaUtilLogManager.logger;
	}

	
	
	
	
	
}
